%% US Public Debt and Safe Asset Market Power
%% Jason Choi, Rishabh Kirpalani, and Diego Perez
%% Nov 21, 2024

%% Print tex tables for paper

clear; dynare monopoly
clear; dynare competitive
clear; dynare fringe_monopoly
clear; dynare fringe_competitive

load me_save 
load ce_save
load me_fringe_save
load ce_fringe_save

fileID = fopen('moncecomp.tex','w');
ddata = [b_sme b_sce b_smef b_scef bf_smef bf_scef spread_sme*100 spread_sce*100 spread_smef*100 spread_scef*100 rb_sme*100 rb_sce*100 rb_smef*100 rb_scef*100];
fprintf(fileID,'\\begin{tabular}{l>{\\centering}p{2.5cm}>{\\centering}p{2.5cm}>{\\centering}p{2.5cm}>{\\centering}p{2.5cm}} \n \\toprule \n & \\multicolumn{2}{c}{Baseline Monopoly Model} & \\multicolumn{2}{c}{Model with Domestic Fringe}\\tabularnewline \n \\midrule \n & Monopoly Equilibrium & Price-taking Equilibrium & Monopoly Equilibrium & Price-taking Equilibrium \\tabularnewline \n \\midrule \n US public debt & $%3.2f$ & $%3.2f$ & $%3.2f$ & $%3.2f$ \\tabularnewline \n Private safe assets & $N/A$ & $N/A$ & $%3.2f$ & $%3.2f$ \\tabularnewline \n \\midrule \n Convenience yield & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ \\tabularnewline \n Interest rate on public debt & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ \\tabularnewline \n \\bottomrule \n \\end{tabular}',ddata);
fclose(fileID);

%----------------------------------------------------------------
%----------------------------------------------------------------

clear; dynare competitive
clear; dynare nobenefit

clear; dynare fringe_competitive
clear; dynare fringe_nobenefit

load ce_save
load nof_save
load ce_fringe_save
load nof_fringe_save

fileID = fopen('welfare.tex','w');
ddata = [Gamma_nobenefit_us Gamma_nobenefit_fringe_us Gamma_competitive_us Gamma_competitive_fringe_us Gamma_competitive_rw Gamma_competitive_fringe_rw];
fprintf(fileID,'\\begin{tabular}{>{\\centering}p{1cm}l>{\\centering}p{3.5cm}>{\\centering}p{3.5cm}} \n \\toprule \n \\multicolumn{2}{l}{US Welfare losses} & Baseline Monopoly Model & Model with Domestic Fringe \\tabularnewline \n \\midrule \n & No exorbitant privilege & $%3.2f\\%%$ & $%3.2f\\%%$ \\tabularnewline \n & No market power in safe assets & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n \\midrule  \n \\multicolumn{2}{l}{RoW welfare gains} &  & \\tabularnewline \n \\midrule \n & No market power in safe assets & $+%3.2f\\%%$ & $+%3.2f\\%%$ \\tabularnewline \n \\bottomrule \n \\end{tabular}',ddata);
fclose(fileID);

%----------------------------------------------------------------
%----------------------------------------------------------------

clear; dynare cournot1
clear; dynare cournot2
clear; dynare cournot3

load me1_save
load me2_save
load me3_save

fileID = fopen('cournot.tex','w');
ddata = [b_sme1 b_sme2 b_sme3 bus_sme1 bus_sme2 bus_sme3 spread_sme1 spread_sme2 spread_sme3 rb_sme1 rb_sme2 rb_sme3 Gamma_me2_us Gamma_me3_us Gamma_me2_rw Gamma_me3_rw];
fprintf(fileID,'\\begin{tabular}{lccc} \n \\toprule \n & \\multirow{2}{*}{Monopoly} & \\multicolumn{2}{c}{Cournot}\\tabularnewline \n &  & $N=2$ & $N=3$\\tabularnewline \n \\midrule \n \\multicolumn{4}{l}{\\emph{a. Steady-state variables}{\\small{}\\vspace{.5em}}}\\tabularnewline \n Total safe assets{\\small{}\\vspace{.5em}} & $%3.2f$ & $%3.2f$ & $%3.2f$\\tabularnewline \n US public debt{\\small{}\\vspace{.5em}} & $%3.2f$ & $%3.2f$ & $%3.2f$\\tabularnewline \n Convenience yield{\\small{}\\vspace{.5em}} & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n Interest rate on public debt{\\small{}\\vspace{.5em}} & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n \\multicolumn{4}{l}{\\emph{b. Welfare}{\\small{}\\vspace{.5em}}}\\tabularnewline \n US welfare{\\small{}\\vspace{.5em}} & $-$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n RoW welfare{\\small{}\\vspace{.5em}} & $-$ & $+%3.2f\\%%$ & $+%3.2f\\%%$\\tabularnewline \n \\bottomrule \n \\end{tabular}',ddata);
fclose(fileID);

%----------------------------------------------------------------
%----------------------------------------------------------------

clear; dynare monopoly
clear; dynare competitive
clear; dynare monopoly_altbenefit
clear; dynare competitive_altbenefit
clear; dynare monopoly_beta
clear; dynare competitive_beta

clear; dynare monopoly_lambdaL
clear; dynare competitive_lambdaL
clear; dynare monopoly_lambdaH
clear; dynare competitive_lambdaH
clear; dynare monopoly_etaL
clear; dynare competitive_etaL
clear; dynare monopoly_etaH
clear; dynare competitive_etaH

load me_save
load ce_save
load me_alt_save
load ce_alt_save
load me_eta_save
load ce_eta_save
load me_ll_save
load ce_ll_save
load me_lh_save
load ce_lh_save
load me_el_save
load ce_el_save
load me_eh_save
load ce_eh_save

fileID = fopen('bigtable.tex','w');
ddata = [b_sme b_sce spread_sme*100 spread_sce*100 rb_sme*100 rb_sce*100 b_me_alt b_ce_alt spread_me_alt*100 spread_ce_alt*100 rb_me_alt*100 rb_ce_alt*100 b_me_eta b_ce_eta spread_me_eta*100 spread_ce_eta*100 rb_me_eta*100 rb_ce_eta*100 b_me_ll b_ce_ll spread_me_ll*100 spread_ce_ll*100 rb_me_ll*100 rb_ce_ll*100 b_me_lh b_ce_lh spread_me_lh*100 spread_ce_lh*100 rb_me_lh*100 rb_ce_lh*100 b_me_el b_ce_el spread_me_el*100 spread_ce_el*100 rb_me_el*100 rb_ce_el*100 b_me_eh b_ce_eh spread_me_eh*100 spread_ce_eh*100 rb_me_eh*100 rb_ce_eh*100]';  
fprintf(fileID,'\\begin{tabular}{lcccccc} \n \\toprule  \n & \\multicolumn{2}{c}{Total safe assets} & \\multicolumn{2}{c}{Convenience yield} & \\multicolumn{2}{c}{Interest rate on public debt}\\tabularnewline \n & Monopoly & Price-taking & Monopoly & Price-taking & Monopoly & Price-taking\\tabularnewline \n \\midrule  \n Baseline & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n Alternative benefit function & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n Model with $\\eta$ shocks & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n Low cost elasticity $\\left(\\lambda=0\\right)$ & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n High cost elasticity $\\left(\\lambda=2\\right)$ & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n Low demand elasticity $\\left(\\varepsilon_{D}=1.5\\right)$ & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n High demand elasticity $\\left(\\varepsilon_{D}=3.2\\right)$ & $%3.2f$ & $%3.2f$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n \\bottomrule \n \\end{tabular}',ddata);
fclose(fileID);

%----------------------------------------------------------------
%----------------------------------------------------------------

clear; dynare monopoly
clear; dynare competitive
clear; dynare nobenefit
clear; dynare monopoly_altbenefit
clear; dynare competitive_altbenefit
clear; dynare nobenefit_altbenefit

load me_save
load ce_save
load nof_save
load me_alt_save
load ce_alt_save
load nof_alt_save

fileID = fopen('alt_welfare.tex','w');
ddata = [Gamma_nobenefit_us Gamma_nobenefit_us_alt Gamma_competitive_us Gamma_competitive_us_alt Gamma_competitive_rw Gamma_competitive_rw_alt]';
fprintf(fileID,'\\begin{tabular}{>{\\centering}p{1cm}lcc} \n \\toprule \n \\multicolumn{2}{l}{US Welfare losses} & Baseline & Alternative benefit function\\tabularnewline \n \\midrule \n & No exorbitant privilege & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n & No market power in safe assets & $%3.2f\\%%$ & $%3.2f\\%%$\\tabularnewline \n \\midrule  \n \\multicolumn{2}{l}{RoW welfare gains} &  & \\tabularnewline \n \\midrule \n & No market power in safe assets & $+%3.2f\\%%$ & $+%3.2f\\%%$\\tabularnewline \n \\bottomrule \n \\end{tabular}',ddata);
fclose(fileID);
